package juc.锁.LockSupport;

import java.util.concurrent.locks.LockSupport;

public class LockSupport_DEMO_1 {
    public static void main(String[] args) throws InterruptedException {
        MyLockSupport supportThread = new MyLockSupport();
        supportThread.start();

        Thread.sleep(100L);
        LockSupport.unpark(supportThread);
    }
}

class MyLockSupport extends Thread {
    private int num = 0;

    @Override
    public void run() {
        while (true) {
            num++;
            System.out.println("num = " + num);

            try {
                Thread.sleep(10L);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }

            //根据条件，设置挂起当前线程
            if (num >= 20) {
                System.out.println("now, thread is parked!");
                LockSupport.park();
                num = 10;
            }
        }
    }
}